define(['jquery','api','user','util'],function($,api,user,util){
	var vm, 
	    startid,
	   controller = {
		   init:function(){
		   	   if(!user.checkLogin())return;
		   	   api.footerShow(0);//隐藏底部导航
			   api.setTitle(L('html_title_user_customer'));
			   	api.headerShow(1);
				api.headerTitle(L('html_title_user_customer'));
			   this.render();
		   },
		   render:function(){
		   	   var that=this;
		   	   $('#common').html('<div id="customer"></div>');
		       require(['text!pages/user/customer.html','Vue'],function(tpl,Vue){
		            vm=new Vue({
		               el:'#customer',
		               data:{
		               	  show:true,
		               	  loading:false,
		               	  showMore:false,
		               	  rows:[],
		               	  form: {
                                username: '',
                                startTime:'',
                    			endTime:'',
                    			level:'1'
                            }
		               },
		               methods:{
		                  doQuery:function(more){
		                  	if(more === undefined){
				                this.rows=[];
			                    startid=0;
			                }
			              	that.load();
			              }
		               },
		               template:tpl
		            });
		       })
		   },
		   load:function(){
		   	vm.loading=true;
		   	  var rows,
		   	      len,
		   	      pageSize=20,
		   	      data = {
                        username: vm.form.username,
//                      returnresulttype: 49,
//                      pagestart: 0,
                        startuid:startid,
                        count: pageSize,
                        level:vm.form.level
                   };
		   	      
		   	  api.customer(data,function(rs){
//		   	  api.customer({username:username,startuid:startid,count:count,mobile:''},function(rs){
		   	  	   vm.loading=false;
		   	       if(rs.retcode=='0' && rs.data){
		   	            rows=rs.data;
	                    vm.rows=vm.rows.length?vm.rows.concat(rows):rows;
	                    var len = rows.length;
	                    startid+=len;
	                    
	                    if(len>=pageSize){
	                       vm.showMore=true;
	                    }else{
	                       vm.showMore=false;
	                    }
		   	            
		   	       }else{
	   	          	util.msg('无更多数据');
	   	            vm.showMore=false;
	   	          }
		   	  });
		   },
		   onRouteChange:function(){
		       if(vm)vm.show=false;
		   }
		}
    return controller;
})